package service

import (
	"fmt"
	"go-demo/common"
	"go-demo/dao"
	"go-demo/model"
	"path/filepath"
)

func UploadVideo(token string, filename string, title string) (string, string) {
	user := common.UsersLoginInfo[token]                                         //根据token获取用户对象
	finalName := fmt.Sprintf("%d_%s", user.Id, filename)                         // 配置视频名字
	saveFile := filepath.Join("./public/", finalName)                            //视频存放地址
	dao.CreateVideo(user.Id, common.Url+common.Port+"/static/"+finalName, title) //将视频地址添加进数据库表Video
	return saveFile, finalName
}

func GetVideos(userid int64) (videoLists []model.Video) {
	videos, _ := dao.GetVideoByUser(userid)
	videoList := GetVideoList(videos)
	return videoList
}
